/*
 * -------------------------------------------------------------------------- *
 * This is a Practice Work from the 'Algorithms, Part-I' course form Coursera.
 * 
 * -------------------------------------------------------------------------- *
 * Date:	29-Aug-2013 8:42:15 am
 */
package com.gs.coursera.algorithms.week.one.uf;

import com.gs.coursera.algorithms.util.ArrayUtils;

/**
 * @author Sabuj Das | sabuj.das@gmail.com
 *
 */
public abstract class UnionFind {

	private final int[] nodes;
	
	public UnionFind(int n) {
		nodes = new int[n];
		ArrayUtils.initArrayWithIndex(nodes);
	}

	public int[] getNodes() {
		return nodes;
	}

	public int getTotalNoOfNodes() {
		return nodes.length;
	}
	
	public abstract void union(int p, int q);
	public abstract boolean isConnected(int p, int q);
	
	public void print(){
		for (int i = 0; i < nodes.length; i++) {
			System.out.print(nodes[i] + " ");
		}
		System.out.println();
	}
}
